package com.hiv.mapper;

import com.hiv.common.param.page.PageQueryBarCodeParam;
import com.hiv.mapper.domain.BarCode;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 条码Mapper接口
 * 
 * @author zhanghong
 * @date 2022-09-20
 */
@Mapper
@Repository
public interface BarCodeMapper {
    BarCode selectById(Long id);
    List<BarCode> selectList(BarCode barCode);
    int insert(BarCode barCode);
    int batchInsert(List<BarCode> barCodeList);
    int update(BarCode barCode);
    int deleteById(Long id);
    int deleteByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from bar_code",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.code!=null and param.code!=''\">and code like concat('%',#{param.code},'%')</if>",
            "       <if test=\"param.hospitalId!=null\">and hospital_id=#{param.hospitalId}</if>",
            "       <if test=\"param.checkType!=null\">and check_type=#{param.checkType}</if>",
            "       <if test=\"param.status!=null\">and status=#{param.status}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") PageQueryBarCodeParam param);
    @Select({"<script>",
            "   select * from bar_code",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.code!=null and param.code!=''\">and code like concat('%',#{param.code},'%')</if>",
            "       <if test=\"param.hospitalId!=null\">and hospital_id=#{param.hospitalId}</if>",
            "       <if test=\"param.checkType!=null\">and check_type=#{param.checkType}</if>",
            "       <if test=\"param.status!=null\">and status=#{param.status}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<BarCode> pageQuery(@Param("param") PageQueryBarCodeParam param, @Param("limit") int limit, @Param("offset") long offset);

    @Update("update bar_code set status=#{status} where id=#{id}")
    Integer updateStatusById(@Param("id") Long id, @Param("status") int status);

    @Select("select * from bar_code where code=#{code} limit 1")
    BarCode queryByCode(String code);
}
